package com.simon.hse.activity.risk;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.google.gson.Gson;
import com.simon.hse.R;
import com.simon.hse.activity.BaseActivity;
import com.simon.hse.http.CommonCallBack;
import com.simon.hse.http.HttpManager;
import com.simon.hse.http.entity.ProcessDetailOutput;
import com.simon.hse.utils.ToastUtils;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;

import retrofit2.Call;

/**
 * 工艺介质-详情
 */
@SuppressWarnings("all")
@ContentView(R.layout.activity_risk_technology_detail)
public class RiskTechnologyDetailActivity extends BaseActivity {
    @ViewInject(R.id.tv_common_title)
    TextView mTv_common_title;

    @ViewInject(R.id.tv_function_6_feature)
    TextView mTv_function_6_feature;

    @ViewInject(R.id.tv_function_6_guide)
    TextView mTv_function_6_guide;

    @ViewInject(R.id.tv_function_6_deviation)
    TextView mTv_function_6_deviation;

    @ViewInject(R.id.tv_function_6_level)
    TextView mTv_function_6_level;

    @ViewInject(R.id.tv_function_6_describe)
    TextView mTv_function_6_describe;

    @ViewInject(R.id.tv_function_6_factor)
    TextView mTv_function_6_factor;

    @ViewInject(R.id.tv_function_6_control)
    TextView mTv_function_6_control;

    private String id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mTv_common_title.setText("工艺介质");
        Bundle bundle = getIntent().getExtras();
        if (bundle == null)
            return;
        id = bundle.getString("ID");
        initDetail();
    }


    @Event(value = {R.id.iv_common_left})
    private void clickButton(View view) {
        switch (view.getId()) {
            case R.id.iv_common_left:
                finish();
                break;
        }
    }

    /**
     * 工艺介质-详情
     */
    private void initDetail() {
        Call<String> call = HttpManager.getInstance().requestService().PROCESS_DETAIL(id);
        HttpManager.getInstance().requestCallBack(call, new CommonCallBack<String>() {
            @Override
            public void requestSuccess(String result) {
                ProcessDetailOutput equipmentDetailOutput  = new Gson().fromJson(result, ProcessDetailOutput.class);
                if (equipmentDetailOutput.getResult().equals("Success")) {
                    final ProcessDetailOutput.DataBean dataBean = equipmentDetailOutput.getData();
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            mTv_function_6_feature.setText(dataBean.getFeatureCharacteristics());
                            mTv_function_6_guide.setText(dataBean.getGuideWord());
                            mTv_function_6_deviation.setText(dataBean.getDeviation());
                            mTv_function_6_level.setText(dataBean.getRiskLevelText());
                            mTv_function_6_describe.setText(dataBean.getRisk());
                            mTv_function_6_factor.setText(dataBean.getHazardousFactor());
                            mTv_function_6_control.setText(dataBean.getControlRequirement());
                        }
                    });
                } else {
                    ToastUtils.getInstance().showShortToastBottom(equipmentDetailOutput.getMessage());
                }
            }

            @Override
            public void requestError(String errorMsg) {
                ToastUtils.getInstance().showShortToastBottom(errorMsg);
            }
        });
    }
}